'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 1_study_function_call_output.py
* @Time: 2025/10/31
* @All Rights Reserve By Brtc
'''
from typing import Literal

import dotenv
from langchain_openai import ChatOpenAI
from pydantic import Field, BaseModel
dotenv.load_dotenv()
class RouteQuery(BaseModel):
    """将用户查询映射到最相关的数据"""
    datasource:Literal["python_docs", "js_docs", "golang_docs"] = Field(
        description="根据用户问题，选择那个数据源最相关，以回答他们的问题"
    )
llm = ChatOpenAI(model="gpt-4o-mini",temperature=0)
struct_llm = llm.with_structured_output(RouteQuery)
#3、执行相应的提问,检查映射路由
question = """ 
为什么下面的代码不工作了，请帮我检查下：
 
from langchain_core.prompts import ChatPromptTemplate
 
prompt = ChatPromptTemplate.from_messages(["human", "speak in {language}"])
prompt.invoke("中文")
"""
res = struct_llm.invoke(question)
#4、选择不同的路由
print(res)
print(type(res))
print(res.datasource)

